package o;

import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.fastengine.fastview.startFastappEngine.bean.RpkInfo;
import com.huawei.hms.framework.network.restclient.hianalytics.HianalyticsData;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Pattern;

class bni {
    private static bna ˊ;
    private static ExecutorService ˋ = Executors.newSingleThreadExecutor();
    private static final Pattern ॱ = Pattern.compile("^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$");

    bni() {
    }

    public static boolean ॱ(String str) {
        return ॱ.matcher(str).matches();
    }

    public static void ˊ(Map<String, String> map, SessionDownloadTask sessionDownloadTask, SplitTask splitTask) {
        if (Integer.parseInt((String) map.get("errorCode")) != 129) {
            ˎ(ˏ(map, sessionDownloadTask, splitTask));
        }
    }

    private static Map<String, String> ˏ(Map<String, String> map, SessionDownloadTask sessionDownloadTask, SplitTask splitTask) {
        Object obj = "";
        Object obj2 = "";
        if (ˊ != null) {
            obj = ˊ.ˋ();
            obj2 = ˊ.ˊ();
        }
        map.put("hcrid", obj);
        map.put("businessType", obj2);
        map.put("probeTime", ˎ());
        map.put(HwAccountConstants.EXTRA_OPLOG_NETTYPE, bny.ˎ());
        map.put("mobileInfo", bny.ʻ());
        map.put("wifiSignalLevel", String.valueOf(bny.ʼ()));
        map.put("resourcePath", "AppDownloadProcess");
        map.put("operationType", String.valueOf(2));
        map.put("cdnReportVersion", "1.3");
        map.put("taskId", String.valueOf(sessionDownloadTask.ʾ()));
        map.put("taskPackageName", sessionDownloadTask.ˊˊ());
        map.put("taskAppId", sessionDownloadTask.ॱˋ());
        map.put("dlPolicy", String.valueOf(sessionDownloadTask.ॱʻ()));
        map.put("hasInterrupt", sessionDownloadTask.ͺ().ॱ() ? "1" : "0");
        map.put("dlType", String.valueOf(sessionDownloadTask.ˌ()));
        map.put("isforeground", sessionDownloadTask.ॱˎ() ? "1" : "0");
        if (splitTask != null) {
            map.put("taskSize", String.valueOf(splitTask.ʼॱ()));
            map.put("isDiff", splitTask.ʾ() == 1 ? "1" : "0");
            map.put("httpProtocol", String.valueOf(splitTask.ˋˊ()));
            URL url = null;
            try {
                if (splitTask.ͺ() != null) {
                    url = new URL(splitTask.ͺ());
                } else if (splitTask.ॱˋ() != null) {
                    url = new URL(splitTask.ॱˋ());
                } else {
                    bnc.ˎ.ˎ("CdnUtils", "Url and DownloadUrl are null");
                }
                if (url != null) {
                    map.put(HianalyticsData.DOMAIN, url.getHost());
                    map.put(RpkInfo.DOWNLOAD_URL, url.toString());
                }
            } catch (MalformedURLException e) {
                bnc.ˎ.ˊ("CdnUtils", "getCdnReportData create url error:" + e.getMessage());
            }
        }
        return map;
    }

    private static void ˎ(final Map<String, String> map) {
        if (bnl.ˏ().ʽ() && ˋ() != null) {
            if (Integer.parseInt((String) map.get("errorCode")) == 200) {
                ˊ.ˋ(map);
            } else {
                ˋ.execute(new Runnable() {
                    public void run() {
                        int parseInt = Integer.parseInt((String) map.get("errorCode"));
                        if (bni.ॱ(parseInt)) {
                            boolean ॱ = doo.ॱ(cvx.ˎ("ota.host"), 443);
                            String valueOf = String.valueOf(doo.ˋॱ(bnl.ˏ().ॱ()));
                            map.put("wifiSignalLevel", valueOf);
                            String ˏ = bny.ˏ();
                            map.put("dnsConfig", ˏ);
                            map.put("netOk", ॱ ? "1" : "0");
                            bnc.ˎ.ˋ("CdnUtils", "cdnReport, dns:" + ˏ + ", isNetOK:" + ॱ + ", wifiSignalLevel:" + valueOf);
                        }
                        if (parseInt == 112 || parseInt == 119) {
                            String str = (String) map.get(HianalyticsData.DOMAIN);
                            if (!dof.ˋ(str)) {
                                map.put("errorMessage", ((String) map.get("errorMessage")) + bni.ˋ(str));
                            }
                        }
                        if (bni.ˋ() != null) {
                            bni.ˊ.ˋ(map);
                        }
                    }
                });
            }
        }
    }

    public static String ˋ(String str) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("[");
        try {
            for (InetAddress hostAddress : InetAddress.getAllByName(str)) {
                stringBuilder.append(hostAddress.getHostAddress()).append(",");
            }
        } catch (UnknownHostException e) {
            bnc.ˎ.ˊ("CdnUtils", "parseHostGetIPAddress  UnknownHostException,  host = " + str);
        }
        stringBuilder.append("]");
        return stringBuilder.toString();
    }

    public static String ˎ() {
        String str = "yyyy-MM-dd HH:mm:ss";
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }

    private static boolean ॱ(int i) {
        if (i == 112 || i == 1133 || i == 1135 || i == 1136 || i == 1137) {
            return true;
        }
        return false;
    }

    public static bna ˋ() {
        return ˊ;
    }

    public static void ˊ(bna o_bna) {
        ˊ = o_bna;
    }
}
